package com.outsourcing.bottle.util;

import android.app.Service;
import android.content.Intent;

import com.outsourcing.bottle.BasicActivity;

/**
 * 
 * @author 06peng
 *
 */
public class UICore {

	private static UICore ins = new UICore();
	private BottlePushService service;
	
	private UICore() {
		
	}

	public static UICore getInstance() {
		if (ins == null) {
			ins = new UICore();
		}
		return ins;
	}
	
	public static void eventTask(BasicUIEvent basicUIEvent,
			BasicActivity context, int CommandID, String tips, Object obj) {
		try {
			CommandTaskEvent commandTask = new CommandTaskEvent(basicUIEvent, context, tips);
			commandTask.execute((new Object[] { CommandID + "", obj }));
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("cancel:  success!!");
			if (context != null)
				context.destroyDialog();
		}
	}

	public static void eventTask(BasicUIEvent basicUIEvent, Service service, int CommandID, String tips, Object obj) {
		try {
			CommandTaskEvent commandTask = new CommandTaskEvent(basicUIEvent, service);
			commandTask.execute((new Object[] { CommandID + "", obj }));
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("cancel:  success!!");
		}
	}
	
	public static void setService(BottlePushService service) {
		UICore.getInstance().service = service;
	}
	
	public static BottlePushService getService() {
		return UICore.getInstance().service;
	}
	
	public void closeService() {
		if (service != null) {
			service.stopService(new Intent(service, BottlePushService.class));
			UICore.setService(null);
			service = null;
		}
	}
}
